<#assign contextPath=springMacroRequestContext.getContextPath() />
<#import "/public/frame/main.html" as frame />
<@frame.head "南航明珠商城-员工列表">
</@frame.head>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 后台管理中心 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 调查问卷管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
<form method="post" name="query_questionnaire_form"  id="query_questionnaire_form" action="${contextPath}/questionnaire/questionnaire_list" >    
   <input type="hidden" name="page" value="${pagination.pageNo}"  id="page" />                        
    <div class="text-c">
        <table class="table">
           <tr>  
           <td>问卷名称：</td>
           <td><input type="text" class="input-text  radius"  placeholder="问卷名称" id="" name="name" value="${questionnaireQo.name}"></td>     
           <td>问卷有效期：</td>
           <td><input  type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'endDate\')}',readOnly: true })" id="startDate" 
               value='${(questionnaireQo.startDate?string("yyyy-MM-dd"))!}' name="startDate"  class="input-text Wdate" style="width:120px;">
                                                至
               <input  type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'startDate\')}',readOnly: true })" id="endDate" 
               value='${(questionnaireQo.endDate?string("yyyy-MM-dd"))!}' name="endDate"    class="input-text Wdate" style="width:120px;">
           </td>
          </tr>
          <tr>
               <td>问卷状态：</td>
           	   <td>
           
	           <span class="select-box radius">
	           <select class="select"  name="state" id="state">
	           	<option value>请选择状态</option>
				<#list stateMap?keys as testKey>
				<#if testKey=questionnaireQo.state>
				<option value="${testKey}" selected="selected">${stateMap[testKey]}</option>
				<#else>
				<option value="${testKey}" >              	${stateMap[testKey]}
     			</option>
				</#if>
				</#list>
	           </select>
	           </span>
	           </td> 
	           <td>显示状态：</td>
           	   <td>
           
	           <span class="select-box radius">
	           <select class="select"  name="showState" id="showState">
	           <option value>请先选择状态</option> 
	           	<#list showStateMap?keys as testKey>
	            <#if testKey=questionnaireQo.showState>
				<option value="${testKey}" selected="selected">${showStateMap[testKey]}</option>
				<#else>
				<option value="${testKey}" >              	${showStateMap[testKey]}
     			</option>
				</#if>

				</#list>
	           </select>
	           </span>
	           </td> 
          </tr>
         <tr> 
         <td colspan="6" style="text-align:center;" >
           <input class="btn btn-success radius" type="button"  onclick="search();"  value="搜索" />
         </td>
         </tr>
      </table>
    </div>
</form>

    <div class="cl pd-5 bg-1 bk-gray mt-20"> 
    <span class="l">
     <a href="javascript:;" onclick="add()" class="btn btn-primary radius"> 新增</a> 
    </span>
    <span class="r">共有数据：<strong>${pagination.totalCount}</strong> 条</span> </div>
    <table class="table table-border table-bordered table-bg">
        <thead>
        <tr  class="text-c">
            <th >调查问卷名称</th>
            <th >发布人</th>
            <th >开始时间</th>
            <th >结束时间</th>
            <th >状态</th>
            <th >显示状态</th>
            <th >操作</th>
        </tr>
        </thead>
        <tbody>
       <#if pagination.list?? && (pagination.list?size &gt; 0) >
        <#list pagination.list as questionnaire> 
             <tr  class="text-c">
                <td>${questionnaire.name}</td>
                <td>${questionnaire.createUser.loginName}</td>
                <td>${(questionnaire.startDate?string("yyyy-MM-dd"))!}</td>
                <td>${(questionnaire.endDate?string("yyyy-MM-dd"))!}</td>
                <td width="55">    
                <#list stateMap?keys as testKey>
                     <#if questionnaire.state=testKey>
                     ${stateMap[testKey]}
                     </#if> 
				</#list>                                    
                </td>
                <td width="55">   
                <#list showStateMap?keys as testKey>
                     <#if questionnaire.showState=testKey>
                    ${showStateMap[testKey]}
                     </#if> 
              	    <#if !(questionnaire.showState)??>
                  		  隐藏
                     </#if> 
				</#list>                                     
                </td>
                <td>					

               	
	    		<#if questionnaire.state == 0 || questionnaire.state == 1>
					<a style="color:blue" href="#" onclick="toAudit('${questionnaire.id}')">审核</a>&nbsp;&nbsp;
				</#if>
				<#if questionnaire.state == 0 || questionnaire.state == 1 || (questionnaire.state == 2 && questionnaire.showState == 1 && questionnaire.startDate?date gt .now?date || (questionnaire.state == 2 && questionnaire.showState == 2))>
					<a style="color:blue" href="#" onclick="toEdit('${questionnaire.id}')">修改</a>&nbsp;&nbsp;
				</#if>
				<#if questionnaire.state == 2 && questionnaire.showState == 1>
					<a style="color:blue" onclick="hideQuestionnaire('${questionnaire.id}')">隐藏</a>&nbsp;&nbsp;
				</#if>
				<#if questionnaire.state == 2 && (questionnaire.showState == 2 || questionnaire.showState == null)>
					<a style="color:blue" onclick="showQuestionnaire('${questionnaire.id}')">显示</a>&nbsp;&nbsp;
				</#if>
				<#if questionnaire.state != 3 && questionnaire.state != 2>
					<a style="color:blue" onclick="deleteQuestionnaire('${questionnaire.id}')">删除</a>&nbsp;&nbsp;
				</#if>
				<#if questionnaire.state == 2 || questionnaire.state == 3>
					<a style="color:blue"  href="${contextPath}/answer/answer_list?id=${questionnaire.id}">查看统计</a>	
				</#if>											
               </td>
        </tr>
      </#list></#if>
     </tbody>
    </table>
    <div id="div_page" style="padding-top: 10px;float: right"></div>
</div>
<@frame.end "default">
</@frame.end>
</html>
<script type="text/javascript" src="${contextPath}/resources/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="${contextPath}/resources/js/laypage/laypage.js"></script>
<script type="text/javascript" src="${contextPath}/resources/js/brand/query_brand.js"></script>
<script type="text/javascript">
var path="${contextPath}";
laypage({
    cont: 'div_page',//容器。值支持id名、原生dom对象，jquery对象。
    pages: ${pagination.totalPage},//通过后台拿到的总页数
    curr:  ${pagination.pageNo} || 1, //当前页
	skip: true, //是否开启跳页
	first: 1, //将首页显示为数字1,。若不显示，设置false即可
	last: ${pagination.totalPage}, //将尾页显示为总页数。若不显示，设置false即可
    jump: function(obj , first){//触发分页后的回调
        if(!first){ //点击跳页触发函数;当前页为obj.curr
            $("#page").val(obj.curr);
            $("#query_questionnaire_form").submit();
        }
    }
})  
function search(){
    $("#page").val("1");
    $("#query_questionnaire_form").submit();
}	
function add(){
	layer_show('添加调查问卷',path+'/questionnaire/add','900','700');
}

function toIsEmpty(){
	document.getElementsByName("name")[0].value= "";
	document.getElementsByName("cname")[0].value= "";
	$("#startDate").val("");
	$("#endDate").val("");
}
function showQuestionnaire(id){
	if(confirm("确定显示吗")){
		var url = path+"/questionnaire/show";
		   $.ajax({
			   url : url,
		   	   type : "post",
		   	   dataType : "text",
		   	   data : {"id":id},
		   	   success : function(msg){
		   		  var resultArr = msg.split(",");
		   		  if(resultArr[0] == "success"){
	                    layer.msg('显示成功!',{icon:1,time:1000},function(){
	                    	 window.location.href=window.location.href;

	                    });
		   			
		   		  }else{
		   			layer.alert(resultArr[1]);
		   		  } 
		   	  },
			  error : function(){
				  layer.alert("操作失败");
			  }
		   });
	   }
}


function hideQuestionnaire(id){
	if(confirm("确定隐藏吗")){
		var url = path+"/questionnaire/hide";
		   $.ajax({
			   url : url,
		   	   type : "post",
		   	   dataType : "text",
		   	   data : {"id":id},
		   	   success : function(msg){
		   		  var resultArr = msg.split(",");
		   		  if(resultArr[0] == "success"){
	                    layer.msg('隐藏成功!',{icon:1,time:1000},function(){
	                    	 window.location.href=window.location.href;

	                    });
		   		  }else{
		   			layer.alert(resultArr[1]);
		   		  } 
		   	  },
			  error : function(){
				  layer.alert("操作失败");
			  }
		   });
	   }
}
function deleteQuestionnaire(id){
	if(confirm("确定删除吗")){
		var url = path+"/questionnaire/delete";
		   $.ajax({
			   url : url,
		   	   type : "post",
		   	   dataType : "text",
		   	   data : {"id":id},
		   	   success : function(msg){
		   		  if(msg=="success"){
	                    layer.msg('删除成功!',{icon:1,time:1000},function(){
	                    	 window.location.href=window.location.href;

	                    });
		   		  }else{
		   			layer.alert("删除失败！");
		   		  }
		   	  },
			  error : function(){
				  layer.alert("操作失败");
			  }
		   });
	   }
}
function toAudit(id){

		 layer.open({
		        type: 2,
		        title: "审核",
		        scrollbar: false,
		        content: path+"/questionnaire/to_audit?id="+id,
		        area: ['800px', '700px']
		    });

	   
}
function toEdit(id){

	 layer.open({
	        type: 2,
	        title: "修改",
	        scrollbar: false,
	        content: path+"/questionnaire/to_edit?id="+id,
	        area: ['800px', '700px']
	    });

  
}
</script>